package com.yunchao.feature.lock.presentation.screen

import android.os.Bundle
import android.view.View
import by.kirich1409.viewbindingdelegate.viewBinding
import com.yunchao.feature.base.presentation.activity.BaseFragment
import com.yunchao.feature.base.presentation.ext.setDebouncedClickListener
import com.yunchao.feature.lock.R
import com.yunchao.feature.lock.databinding.FragmentLockRecoveryBinding
import com.yunchao.feature.lock.domain.model.LockInfoModel

internal class LockRecoveryFragment : LockFragment(R.layout.fragment_lock_recovery) {

    private val binding: FragmentLockRecoveryBinding by viewBinding<FragmentLockRecoveryBinding>()

    override fun initView(view: View, savedInstanceState: Bundle?) {
        binding.textView4.setDebouncedClickListener {
            lockEPCInfo?.apply {
                viewModel.recoveryLock(this)
            }
        }
    }

    override fun handlePageSuccess(lockInfoModel: LockInfoModel) {
        super.handlePageSuccess(lockInfoModel)
        binding.apply {
            if (lockInfoModel.handleResult) {
                lockRecoveryTvAfter.text = getString(
                    com.yunchao.feature.base.R.string.锁号STR,
                    lockInfoModel.lockEPCInfo.id
                )
                lockRecoveryTvAfter1.text = getString(
                    com.yunchao.feature.base.R.string.EPCSTR,
                    lockInfoModel.lockEPCInfo.epc
                )
            } else {
                lockRecoveryTvBefore.text = getString(
                    com.yunchao.feature.base.R.string.锁号STR,
                    lockEPCInfo?.id
                )
                lockRecoveryTvBefore1.text = getString(
                    com.yunchao.feature.base.R.string.EPCSTR,
                    lockEPCInfo?.epc
                )
            }
        }
    }

    override fun handlePageIdle() {
        binding.apply {
            lockRecoveryTvBefore.setText(com.yunchao.feature.base.R.string.锁号)
            lockRecoveryTvBefore1.setText(com.yunchao.feature.base.R.string.EPC)
            lockRecoveryTvAfter.setText(com.yunchao.feature.base.R.string.锁号)
            lockRecoveryTvAfter1.setText(com.yunchao.feature.base.R.string.EPC)
        }
    }
}